"""
@File    :   path.py
@Time    :   2024/01/07 20:00:35
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   路径配置文件
"""

from pathlib import Path

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles


def mount_static_and_upload_path(app: FastAPI):
    """配置静态资源与上传文件资源"""
    from src.config import get_app_settings

    # 获取应用配置
    settings = get_app_settings()
    # 上传路径创建
    upload_dir_path = Path(settings.upload_dir_path)
    if not upload_dir_path.exists():
        upload_dir_path.mkdir()
    # 上传路径配置
    app.mount(
        settings.upload_prefix,
        StaticFiles(directory=settings.upload_dir_path),
        name="upload",
    )
    # 静态资源路径配置
    app.mount(
        settings.static_prefix,
        StaticFiles(directory=settings.static_dir_path),
        name="static",
    )
